var gulp = require('gulp')
var pug = require("gulp-pug")
var stylus = require('gulp-stylus')
var connect = require('gulp-connect')
var coffee = require('gulp-coffee')

gulp.task('build', function() {
  gulp.src([
    'node_modules/jquery/dist/jquery.min.js',
  ]).pipe(gulp.dest('dist/lib'))

  gulp.src('src/tpl/*.pug')
    .pipe(pug({pretty: true}))
    .pipe(gulp.dest('dist'))
    .pipe(connect.reload())

  gulp.src('src/img/*')
    .pipe(gulp.dest('dist/img'))
    .pipe(connect.reload())

  gulp.src('src/css/*')
    .pipe(stylus())
    .pipe(gulp.dest('dist/css'))
    .pipe(connect.reload())

  gulp.src('src/js/*')
    .pipe(coffee())
    .pipe(gulp.dest('dist/js'))
    .pipe(connect.reload())
})

gulp.task('connect', function() {
  connect.server({
    root: 'dist',
    port: 8888,
    livereload: true
  })
})

gulp.task('watch', function(){
  gulp.watch('src/**', ['build'])
})

gulp.task('dev', ['connect', 'watch'])